﻿#include <iostream>
#include <json/json.h>
#include <json/value.h>
#include <json/reader.h>
#include"CServer.h"
#include"configMgr.h"

int main()
{
	try
	{
		auto &configMgr = ConfigMgr::GetInstance();
		std::string gate_port_str = configMgr["GateServer"]["port"];
		unsigned short gate_port = atoi(gate_port_str.c_str());
		net::io_context ioc{ 1 };
		boost::asio::signal_set signals(ioc, SIGINT, SIGTERM);
		signals.async_wait([&ioc](const boost::system::error_code& error, int signal_number) {
			if (error)
			{
				return;
			}
			ioc.stop();
		});
		std::make_shared<CServer>(ioc, gate_port)->Start();
		std::cout << "GateServer is running on port: " << gate_port << std::endl;
		ioc.run();
    }
	catch (std::exception& exp)
	{
		std::cerr << "Error: " << exp.what() << std::endl;
		return EXIT_FAILURE;
	}
	return 0;
}